<template>
    <div class="right">
        <el-dropdown @command="userDropdown">
            <div class="header-user">
                <span>欢迎，{{$store.state.admin.name}}</span>
            </div>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="refresh" v-if="$store.state.admin.id == 1">
                    <span class="red">刷新缓存</span>
                </el-dropdown-item>
                <el-dropdown-item command="chpw">修改密码</el-dropdown-item>
                <el-dropdown-item command="out">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</template>

<script>
    import {refreshCache} from "@/api";

    export default {
        methods: {
            //退出
            userDropdown(type) {
                switch (type) {
                    case 'refresh':
                        this.$confirm('确定刷新缓存？', () => {
                            refreshCache(() => {
                                this.$message.success('刷新成功');
                            })
                        })
                        break;
                    case 'out':
                        this.$confirm('确定退出登录？', () => {
                            window.localStorage.clear();
                            this.$router.push({name: 'login'});
                        })
                        break;
                    case 'chpw':
                        this.$router.push({name: 'chpw'});
                        break;
                }
            },
        }
    }
</script>
